package com.nineclock.document.service.impl;

import com.nineclock.common.enums.ResponseEnum;
import com.nineclock.common.exception.NcException;
import com.nineclock.common.threadlocal.CurrentUserHolder;
import com.nineclock.common.utils.CountUtil;
import com.nineclock.document.dto.DocFileDto;
import com.nineclock.document.dto.DocFileHistoryDto;
import com.nineclock.document.mapper.DocFileHistoryMapper;
import com.nineclock.document.pojo.DocFile;
import com.nineclock.document.pojo.DocFileHistory;
import com.nineclock.document.service.DocFileHitoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @program: nineclock-group-02
 * @description: ${description}
 * @author: TimLi
 * @create: 2021-07-23 08:46
 **/
@Service
@Slf4j
public class DocFileHitoryServiceImpl implements DocFileHitoryService {

    @Autowired
    DocFileHistoryMapper docFileHistoryMapper;

    @Override
    public void createFileHistory(DocFileDto docFileDto) {
        //健壮性判断
        if (docFileDto==null || docFileDto.getName().length()==0){
            throw new NcException(ResponseEnum.ERROR);
        }

        // 设置前端传递过来的参数
        DocFileHistory docHIstoryFile = new DocFileHistory();
        //内容
        docHIstoryFile.setContent(docFileDto.getContent());
        //名字
        docHIstoryFile.setFileName(docFileDto.getName());
        //设置创建用户id
        docHIstoryFile.setFileId(CurrentUserHolder.get().getCompanyUserId());

        //创建时间 表中有默认值
        docHIstoryFile.setOperateTime(new Date());

        //更新用户id
        docHIstoryFile.setOperateUserId(CurrentUserHolder.get().getCompanyUserId());

        docHIstoryFile.setIsCreate((short)1);


        docFileHistoryMapper.insert(docHIstoryFile);
    }
}
